#include "InputTypes.h"
#include "qtutilities.h"

ButtonType::ButtonType()
  : mType(TYPE_UNKNOWN),
    mKeyboard(Qt::Key_unknown),
    mGamepad(0),
    mGamepadNumber(0)
{
}

ButtonType::ButtonType(Type t, int i, unsigned int gamepadNumber)
  : mType(t),
    mKeyboard(static_cast<Qt::Key>(i)),
    mGamepad(i),
    mGamepadNumber(gamepadNumber)
{
}

QString ButtonType::toString() const
{
  QString ret;

  switch(mType)
  {
  case TYPE_UNKNOWN:
    ret = "Unknown";
    break;
  case TYPE_KEYBOARD:
    ret = QString("Keyboard Button ")+QtUtilities::key2str(mKeyboard);
    break;
  case TYPE_GAMEPAD:
    ret = "Gamepad "+QString::number(mGamepadNumber)+" Button "+QString::number(mGamepad);
    break;
  }

  return ret;
}

bool ButtonType::operator ==(const ButtonType& bt) const
{
  return mType == bt.mType &&
         mKeyboard == bt.mKeyboard &&
         mGamepad == bt.mGamepad &&
         mGamepadNumber == bt.mGamepadNumber;
}

HalfAxisType::HalfAxisType()
  : mType(TYPE_UNKNOWN),
    mGamepadAxis(0),
    mDirection(DIRECTION_POS),
    mGamepadNumber(0)
{
}

QString HalfAxisType::toString() const
{
  QString ret;

  switch(mType)
  {
  case TYPE_UNKNOWN:
    ret = "Axis Unknown";
    break;
  case TYPE_BUTTON:
    ret = QString("Axis ")+mButton.toString();
    break;
  case TYPE_AXIS:
    ret = QString("Axis ")+static_cast<char>(mDirection)+QString::number(mGamepadAxis)
          +" Gamepad "+QString::number(mGamepadNumber);
    break;
  }

  return ret;
}

bool HalfAxisType::operator ==(const HalfAxisType& hat) const
{
  return mType == hat.mType &&
         mButton == hat.mButton &&
         mGamepadAxis == hat.mGamepadAxis &&
         (mDirection == hat.mDirection || mDirection == DIRECTION_NONE || hat.mDirection == DIRECTION_NONE) &&
         mGamepadNumber == hat.mGamepadNumber;
}

bool HalfAxisType::operator !=(const HalfAxisType& hat) const
{
  return !operator==(hat);
}

QString AxisType::toString() const
{
  return "+"+mPos.toString()+"\n"
         "-"+mNeg.toString();
}
